package com.ruoyi.web.controller.recipe;

import java.util.List;

import com.ruoyi.recipe.domain.RecipeDish;
import com.ruoyi.recipe.service.IRecipeDishService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recipe.domain.RecipeDishMeal;
import com.ruoyi.recipe.service.IRecipeDishMealService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 婴儿辅食Controller
 * 
 * @author ruoyi
 * @date 2024-12-10
 */
@Controller
@RequestMapping("/recipe/meal")
public class RecipeDishMealController extends BaseController
{
    private String prefix = "recipe/meal";

    @Autowired
    private IRecipeDishMealService recipeDishMealService;

    @Autowired
    private IRecipeDishService recipeDishService;

    @RequiresPermissions("recipe:meal:view")
    @GetMapping()
    public String meal()
    {
        return prefix + "/meal";
    }

    /**
     * 查询婴儿辅食列表
     */
    @RequiresPermissions("recipe:meal:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecipeDishMeal recipeDishMeal)
    {
        startPage();
        List<RecipeDishMeal> list = recipeDishMealService.selectRecipeDishMealList(recipeDishMeal);
        return getDataTable(list);
    }

    /**
     * 导出婴儿辅食列表
     */
    @RequiresPermissions("recipe:meal:export")
    @Log(title = "婴儿辅食", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecipeDishMeal recipeDishMeal)
    {
        List<RecipeDishMeal> list = recipeDishMealService.selectRecipeDishMealList(recipeDishMeal);
        ExcelUtil<RecipeDishMeal> util = new ExcelUtil<RecipeDishMeal>(RecipeDishMeal.class);
        return util.exportExcel(list, "婴儿辅食数据");
    }

    /**
     * 新增婴儿辅食
     */
    @GetMapping("/add/{dishId}")
    public String add(@PathVariable("dishId") Long dishId, ModelMap mmap)
    {
        RecipeDish recipeDish = recipeDishService.selectRecipeDishByDishId(dishId);
        mmap.put("recipeDish", recipeDish);
        return prefix + "/add";
    }

    /**
     * 新增保存婴儿辅食
     */
    @RequiresPermissions("recipe:meal:add")
    @Log(title = "婴儿辅食", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecipeDishMeal recipeDishMeal)
    {
        return toAjax(recipeDishMealService.insertRecipeDishMeal(recipeDishMeal));
    }

    /**
     * 修改婴儿辅食
     */
    @RequiresPermissions("recipe:meal:edit")
    @GetMapping("/edit/{mealId}")
    public String edit(@PathVariable("mealId") Long mealId, ModelMap mmap)
    {
        RecipeDishMeal recipeDishMeal = recipeDishMealService.selectRecipeDishMealByMealId(mealId);
        mmap.put("recipeDishMeal", recipeDishMeal);
        return prefix + "/edit";
    }

    /**
     * 修改保存婴儿辅食
     */
    @RequiresPermissions("recipe:meal:edit")
    @Log(title = "婴儿辅食", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecipeDishMeal recipeDishMeal)
    {
        return toAjax(recipeDishMealService.updateRecipeDishMeal(recipeDishMeal));
    }

    /**
     * 删除婴儿辅食
     */
    @RequiresPermissions("recipe:meal:remove")
    @Log(title = "婴儿辅食", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recipeDishMealService.deleteRecipeDishMealByMealIds(ids));
    }
}
